#include "contacttlistwidget.h"

ContacttListWidget::ContacttListWidget(QWidget *parent) :
    QTreeWidget(parent)
{
    columnId[StatusColumn] = 0;
    columnId[TextColumn] = 1;
    columnId[MoodColumn] = 2; //TODO: Make it configurable
    showOfflineUsers = false;
    showGroups = false;
}

void ContacttListWidget::addTopLevelItem(ContactListItem *item)
{
    QTreeWidget::addTopLevelItem(item);
}

void ContacttListWidget::itemAdded (const JID &jid, const JID &clientJid)
{
}
void ContacttListWidget::itemSubscribed (const JID &jid, const JID &clientJid)
{

}
void ContacttListWidget::itemRemoved (const JID &jid, const JID &clientJid)
{

}
void ContacttListWidget::itemUpdated (const JID &jid, const JID &clientJid)
{

}
void ContacttListWidget::itemUnsubscribed (const JID &jid, const JID &clientJid)
{

}
void ContacttListWidget::rosterRecieved (const Roster &roster, const JID &clientJid)
{
    qDebug() << "ContacttListWidget::rosterRecieved";
    this->clear();
    LocalRoster::RosterItemPair p;
    foreach(p, roster)
    {
          ContactListItem *item = new ContactListItem(p.first, clientJid);
          QString name = QString::fromStdString(p.second->name());
          if (name.length() == 0)
              name = QString::fromStdString(p.first);
          item->setText(columnId[TextColumn], name);
          item->setText(columnId[StatusColumn], p.second->online()?"Online":"Offline");
          qDebug() << "ContacttListWidget::rosterRecieved->adding item: " << name;
          QTreeWidget::addTopLevelItem(item);
    }
}
void ContacttListWidget::rosterPresence (const RosterItem &item, const QString& resource, Presence::PresenceType presence, const QString& msg, const JID &clientJid)
{

}
void ContacttListWidget::selfPresence (const RosterItem &item, const QString& resource, Presence::PresenceType presence, const QString& msg, const JID &clientJid)
{

}
void ContacttListWidget::subscriptionRequest (const JID &jid, const QString& msg, const JID &clientJid)
{

}
void ContacttListWidget::unsubscriptionRequest (const JID &jid, const QString& msg, const JID &clientJid)
{

}
void ContacttListWidget::nonrosterPresence (const Presence &presence, const JID &clientJid)
{

}
void ContacttListWidget::rosterError (const IQ &iq, const JID &clientJid)
{

}
